package com.sqx.modules.creation.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.Result;
import com.sqx.modules.creation.dao.LabelDao;
import com.sqx.modules.creation.entity.NLabel;
import com.sqx.modules.creation.entity.dto.GetLabelListDto;
import com.sqx.modules.creation.entity.dto.UpdateLabelDto;
import com.sqx.modules.creation.service.LabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.Date;

/**
 * <p>
 * 标签表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024年09月07日
 */
@Service
public class LabelServiceImpl extends ServiceImpl<LabelDao, NLabel> implements LabelService {

    @Autowired
    private LabelDao labelDao;
    @Override
    public Result getLabelList() {
        LambdaQueryWrapper<NLabel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.ne(NLabel::getLabelStatus,2);
        return Result
                .success().put("data", labelDao.selectList(lambdaQueryWrapper));
    }

    @Override
    public Result updateLabel(UpdateLabelDto updateLabelDto) {
        LambdaUpdateWrapper<NLabel> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(NLabel::getLabelId,updateLabelDto.getLabelId());
        lambdaUpdateWrapper.ne(NLabel::getLabelStatus,2);
        lambdaUpdateWrapper.set(NLabel::getLabelName,updateLabelDto.getLabelName());
        lambdaUpdateWrapper.set(NLabel::getUpdateTime,new Date());
        return Result.success();
    }

    @Override
    public Result deleteLabel(Integer[] labelIds) {
        LambdaUpdateWrapper<NLabel> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(NLabel::getLabelId, Arrays.asList(labelIds));
        lambdaUpdateWrapper.set(NLabel::getLabelStatus,0);
        lambdaUpdateWrapper.set(NLabel::getDeleteTime,new Date());
        return Result.success();
    }
}
